var Array_cctv = [];
var Array_Events = [];
function CCTV_IMAEG_BY_MiNiJIK () { 
	Array_cctv = [];
        $.ajax({          
          url: "rest/traffy_image.php",
          success : function (data) {            
            var points = $.parseJSON(data);
            //var points = JSON.parse(data);                                 
            for(var i in points) { 
              if (points.hasOwnProperty(i))
                for(var j in points[i]) {
                  if (points[i].hasOwnProperty(j)) {
                    //console.log(points[i][j]);                   
                    var title = points[i][j].name_th;
                    var url = points[i][j].url;
                    var latitude = points[i][j].point.lat;
                    var longitude = points[i][j].point.lng;
                    var myLatlng = new google.maps.LatLng(latitude,longitude);
                    var format = "&format=ani&available=t"; 
                    
                    var marker = new google.maps.Marker({
                      position: myLatlng,
                      map: map,
                      title:title,
                      url:url+format,
                      icon: 'image/images/camera-motion.png',                    
                      animation: google.maps.Animation.DROP
                    });
                    
                    Array_cctv.push(marker);
                    
                    google.maps.event.addListener(marker, 'click', function(e) {            
                    //console.log(this.url);        
                     ConTent='<div><iframe src="' + this.url + '" width = 450 height = 300></iframe></div>';                                   
                       infowindow = new google.maps.InfoWindow({                    
                        content:ConTent
                      });                  
                    infowindow.open(map,this);                    
                    });   
                  }
                }
            }
          }
        });
      }
function Event() { 
	Array_Events = [];
        $.ajax({
          url: "rest/event.php",
          success : function (data) {
            var Event = $.parseJSON(data);            
            for(var i in Event){
              if (Event.hasOwnProperty(i)) {
                // console.log(Event[i]);
                var type = Event[i].type;
                var latitude  = Event[i].latitude;
                var longitude = Event[i].longitude;
                var description = Event[i].description;
                var title = Event[i].title;
                var timeStart = Event[i].start;
                var timeStop = Event[i].stop;
                var contributor=Event[i].contributor;
                var myLatlng = new google.maps.LatLng(latitude, longitude);
                var construction = 2;
                var accident = 3;
                var trafficjam = 10;
                var carbreakdown = 1;
                var information = 8;
                if (type == carbreakdown) {// type 1
                 var marker = new google.maps.Marker({
                    position: myLatlng,
                    map: map,
                    title:title,
                    timeStart:timeStart,
                    timeStop:timeStop, 
                    description:description,
                    contributor:contributor,         
                    icon: 'image/images/carbreakdown.png'                                       
                  });               
                }
                if (type == construction) {                 
                  var marker = new google.maps.Marker({
                    position: myLatlng,
                    map: map,
                    title:title,
                    timeStart:timeStart,
                    timeStop:timeStop, 
                    description:description,
                    contributor:contributor,         
                    icon: 'image/images/construction.png'                    
                    // animation: google.maps.Animation.DROP,
                  });                 
                }                
                if ( type == accident ) {// type 3
                  var marker = new google.maps.Marker({
                    position: myLatlng,
                    map: map,
                    title:title,
                    timeStart:timeStart,
                    timeStop:timeStop, 
                    description:description,
                    contributor:contributor,         
                    icon: 'image/images/accident.png'                                        
                  });               
                }
                if (type == information) {
                  var marker = new google.maps.Marker({
                    position: myLatlng,
                    map: map,
                    title:title,
                    timeStart:timeStart,
                    timeStop:timeStop,  
                    description:description,
                    contributor:contributor,         
                    icon: 'image/images/information.png'                                        
                  });              
                }
                if ( type == trafficjam ) {
                  var marker = new google.maps.Marker({
                    position: myLatlng,
                    map: map,
                    title:title,
                    timeStart:timeStart,
                    timeStop:timeStop, 
                    description:description,
                    contributor:contributor,         
                    icon: 'image/images/trafficjam.png'                                        
                  });               
                }
                if ( type == '13' ) {
                  var marker = new google.maps.Marker({
                    position: myLatlng,
                    map: map,
                    title:title,
                    timeStart:timeStart,
                    timeStop:timeStop, 
                    description:description,
                    contributor:contributor,         
                    icon: 'image/images/event.png'                                        
                  });                                  
                }

                Array_Events.push(marker);

				google.maps.event.addListener(marker, 'click', function(e){
                    var content="<center><div class='EventTitle'>"+this.title+"</div></center><a>ระหว่างวันที่ : </a><a class='EventTimeStart'>"+this.timeStart+"</a><a> - </a><a class='EventTimeStart'>"+this.timeStop+"</a><a class='EventTimeStart'> โดย </a><a>"+this.contributor+"</a><br><div'>"+this.description+"</div>"; 
                    var infowindow = new google.maps.InfoWindow({                    
                    	content:content
                    });                  
                  infowindow.open(map,this);  
                });
              }
            }           
        }
    });
}